﻿/* ----------------------------------------------------------------------------
 * Copyright (c) Philip Stears 
 *
 * This source code is subject to terms and conditions of the Microsoft Public 
 * License (Ms-PL).
 * 
 * By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 * 
 * To request a copy of the Microsoft Public License, send a request by email
 * to license@connectbasic.net.
 *
 * This notice must not be removed from this software.
 * ---------------------------------------------------------------------------- */

namespace ConnectBasic.Shell.Implementation
{
    using System.Collections.Generic;
    using ConnectBasic.Shell.Extensibility;

    internal class DefaultProjectItemCollection : IProjectItemCollection
    {
        private DefaultProject mProject;
        private List<IProjectItem> mItems = new List<IProjectItem>();

        #region .ctor

        internal DefaultProjectItemCollection(DefaultProject project)
        {
            mProject = project;
        }

        #endregion

        #region IProjectItemCollection Members       
        
        public IProjectItem Add(string name, string typeName)
        {

            // Get the project to do the heavy lifting to actually create
            // the item
            var item = mProject.AddItemInternal(name, typeName);

            // Add it to the collection
            mItems.Add(item);

            // Present it to the caller
            return item;
        }

        public IProjectItem this[int index]
        {
            get { return mItems[index]; }
        }

        public int Count
        {
            get { return mItems.Count; }
        }

        #endregion

        #region IEnumerable<IProjectItem> Members

        public IEnumerator<IProjectItem> GetEnumerator()
        {
            return mItems.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return mItems.GetEnumerator();
        }

        #endregion

    }
}
